package com.tanhua.server.controller;

import com.tanhua.model.dto.RecommendUserDto;
import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.service.TanHuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanHuaController {
    @Autowired
    private TanHuaService tanHuaService;

    /**
     * 查看今日佳人
     *
     * @return
     */
    @GetMapping("/todayBest")
    public ResponseEntity todayBest() {
        TodayBest vo = tanHuaService.todayBest();
        return ResponseEntity.ok(vo);
    }

    /**
     * 推荐朋友
     *
     * @return
     */
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto dto) {
        //分页对象
        PageResult pageResult = tanHuaService.recommendation(dto);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 查看佳人详情
     *
     * @param userId
     * @return
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long userId) {
        TodayBest best = tanHuaService.personalInfo(userId);
        return ResponseEntity.ok(best);
    }

    /**
     * 查看陌生人问题
     *
     * @return
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId) {
        String questions = tanHuaService.findStrangerQuestions(userId);
        return ResponseEntity.ok(questions);
    }

    /**
     * 回复陌生人问题
     *
     * @return
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(@RequestBody Map map) {
        //获取id
        String id = map.get("userId").toString();
        //将字符串的id转换为long类型
        Long userId = Long.valueOf(id);
        String reply = map.get("reply").toString();
        tanHuaService.replyQuestions(userId, reply);
        return ResponseEntity.ok(null);
    }


    /**
     * 探花-左滑右滑
     *
     * @return
     */
    @GetMapping("/cards")
    public ResponseEntity queryCardsList() {
        List<TodayBest> best = this.tanHuaService.queryCardsList();
        return ResponseEntity.ok(best);
    }

    /**
     * 探花右滑喜欢
     *
     * @param likeUserId
     * @return
     */
    @GetMapping("/{id}/love")
    public ResponseEntity setLove(@PathVariable("id") Long likeUserId) {
        this.tanHuaService.setLove(likeUserId);
        return ResponseEntity.ok(null);
    }

    /**
     * 探花左滑不喜欢
     *
     * @param notLikeUserId
     * @return
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity setUnLove(@PathVariable("id") Long notLikeUserId) {
        this.tanHuaService.setUnLove(notLikeUserId);
        return ResponseEntity.ok(null);
    }

    /**
     * 搜附近
     * @param gender
     * @param distance
     * @return
     */
    @GetMapping("/search")
    public ResponseEntity<List<NearUserVo>> search(String gender,
                                                   @RequestParam(defaultValue = "2000") String distance) {
        List<NearUserVo> list = this.tanHuaService.search(gender, distance);
        return ResponseEntity.ok(list);
    }
}
